﻿using DevComponents.DotNetBar.Controls;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.Text;
using System.Windows.Forms;

namespace AppCash
{
    public partial class frmCashSet : Form
    {
        public frmCashSet()
        {
            InitializeComponent();
        }

        private void textBoxX2_KeyUP(object sender, KeyEventArgs e)
        {
            (sender as TextBoxX).Text = e.KeyCode.ToString();
        }

        private void buttonX1_Click(object sender, EventArgs e)
        {
            Dictionary<string, string> keys = new Dictionary<string, string>();
            foreach (Control item in this.Controls)
            {
                if ((item is TextBoxX) || (item is ComboBoxEx )) {
                    keys.Add(item.Name, item.Text);
                }
            }
            string json = JsonConvert.SerializeObject(keys);
            System.IO.File.WriteAllText( System.Environment.CurrentDirectory +"/keyconfig", json);
            ZhiKeDuoServer.Model.GlobalsInfo.PrinterIPAddress = ipaddr.Text;


        }

        private void frmCashSet_Load(object sender, EventArgs e)
        {

            foreach (string sPrint in PrinterSettings.InstalledPrinters)//获取所有打印机名称
            {
                ipaddr.Items.Add(sPrint);
             
            }
            string json= System.IO.File.ReadAllText(System.Environment.CurrentDirectory + "/keyconfig");
            var rlt=JsonConvert.DeserializeObject<Dictionary<string, string>>(json);

            foreach (Control item in this.Controls)
            {
                if ((item is TextBoxX) || (item is ComboBoxEx))
                {
                    item.Text = rlt[item.Name];
                }
            }
        }
    }
}
